package com.sskj.mine;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.MD5Util;
import com.sskj.common.util.SPUtil;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.SPConfig;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.lib.util.CommonUtil;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.presenter.BasePresenter;
import com.sskj.mine.SettingPasswordActivity;


/**
 * @author Hey
 * Create at  2019/05/01
 */
class SettingPasswordPresenter extends BasePresenter<SettingPasswordActivity> {
    /**
     * 请求资金密码验证码
     */
    public void requestSms(String mobile) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.SMS_SEND)
                .params("mobile", mobile)
                .params("type", 4)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        ToastUtil.showShort(body.msg);
                        if (body.status == 200) {
                            mView.onAuthCodeSuccess();
                        }
                    }
                });
    }

    // 获取邮箱验证码
    public void sendEmail(String email) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.SEND_EMAIL)
                .params("email", email)
                .execute(new JsonCallBack<HttpData>(this) {

                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        ToastUtil.showShort(response.body().getMsg());
                        mView.onAuthCodeSuccess();
                    }
                });
    }

    //重置资金密码  登录密码
    public void setPayPwd(String oldPwd, String pwd1, String code, boolean isPayPwd) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + (isPayPwd ? HttpConfig.SET_PAY_PWD : HttpConfig.SET_LOGIN_PWD))
                .params("oldpwd", CommonUtil.getFiveMd5Value(oldPwd))
                .params(isPayPwd ? "tpwd" : "opwd", CommonUtil.getFiveMd5Value(pwd1))
                .params(isPayPwd ? "tpwd1" : "opwd1", CommonUtil.getFiveMd5Value(pwd1))
                .params("type", SPUtil.get(SPConfig.USER_ACCOUNT, "").contains("@") ? 2 : 1)
                .params("code", code)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpListData = response.body();
                        ToastUtil.showShort(httpListData.getMsg());
                        if (httpListData.getStatus() == 200) {
                            mView.updataUI();
                        }
                    }
                });
    }
}
